import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by zhourh on 2018/6/12.
 *
 * 给定一个非负索引 k，其中 k ≤ 33，返回杨辉三角的第 k 行。
 *
 *
 */
public class PascalTriangleII {

    public static void main(String[] args) {
        List<Integer> result = new PascalTriangleII().getRow(8);
        System.out.println(result);
    }

    public List<Integer> getRow(int rowIndex) {
        if (rowIndex < 0) {
            return Collections.emptyList();
        }
        Integer[] row = new Integer[rowIndex + 1];
        Arrays.fill(row, 0);

        for (int i = 0; i <= rowIndex; i++) {
            if (i == 0) {
                row[0] = 1;
                continue;
            }
            for (int j = rowIndex; j >= 1; j--) {
                row[j] = row[j] + row[j - 1];
            }
        }

        return Arrays.asList(row);
    }
}
